
$import("style/css/tips.css","css"); 
//******************************************************
// 包含文件 用法： $import('../include/mian.js', 'js');
//                 $import('../style/style.css', 'css');
//******************************************************
function $import(path, type){
	var i,
	base,
	src = "wowAjax.js",
    scripts = document.getElementsByTagName("script");

 

	for (i = 0; i < scripts.length; i++) {
    	if (scripts[i].src.match(src)) {
	          base = scripts[i].src.replace(src, "");
	          break;
		}
	}
  
  if (type == "css") {
      document.write("<" + "link href=\"" +  base + path + "\" rel=\"stylesheet\" type=\"text/css\"></" + "link>");
  } else {
      document.write("<" + "script src=\"" + base+ path + "\"></" + "script>");
  }
}

function moin(iobj,id){
		timeoutid = setTimeout(function(){showItem(iobj,id);}, 300);
	}
	
function showItem(iobj,itemId){

		
		if(itemId){	
			str = "tips" + itemId;
			
			if(!($("#"+str).attr("id"))){
				
				if(!($("#tips").attr("id"))){
					$('<div></div>').attr("id","tips").appendTo('body');
				}
				$('<div></div>').attr("id",str).addClass("tooltips-over").appendTo('#tips');
				
				
				$('<table></table>').appendTo("#"+str);
				$('<tr></tr>').appendTo("#"+str+" table");
				$('<td><div class="tips-in">正在查找......</div></td>').addClass('onetip').appendTo("#"+str+" table tr:last");
				$('<th></th>').addClass('tip-right').appendTo("#"+str+" table tr:last");
				$('<tr></tr>').appendTo("#"+str+" table");
				$('<th></th>').addClass('tip-botom').appendTo("#"+str+" table tr:last");
				$('<th></th>').addClass('tip-conor').appendTo("#"+str+" table tr:last");
				
				tip1 = tipsposition(iobj,$("#"+str+" table").width(),$("#"+str).height());
				$("#"+str).css({ "top": tip1['mY'] ,"left": tip1['mX']});
						
				$.get(app_url+'/member/itemquery',{item_id:itemId},
					function(s){
						re = eval("("+s+")");
						xml = re['data']['itemTooltips']['itemTooltip'];
						item_string = itemFormat(xml);
						$("#"+str+" table").width(350);
						$("#"+str+" table  .onetip").html(item_string['str']);
						
						tip2 = tipsposition(iobj,$("#"+str+" table").width(),$("#"+str).height());
						
						$("#"+str).css({ "top": tip2['mY'] ,"left": tip2['mX']});
						
						
				});
				
			}
			else{
				$("#"+str).removeClass();
				$("#"+str).addClass("tooltips-over");
			}			
		}
	}
	
function hideItem(itemId){
		str = "tips" + itemId;
		clearTimeout(timeoutid);
		if(($("#"+str).attr("id"))){
			
			$("#"+str).removeClass();
			$("#"+str).addClass("tooltips");
			
		}
	}
	
	
function itemFormat(idata){
		
		
		item_arr = new Array();
		item_arr['name'] = "<p class='q"+idata['overallQualityId']+"'>"+idata['name']+"</p>";
		
		//绑定类型：
		switch (idata['bonding']){
			case "1": 
				item_arr['bonding'] = "<p >拾取后绑定</p>";
				break;
			case "2":
				item_arr['bonding'] = "<p >装备后绑定</p>";
				break;
			default:
				item_arr['bonding'] = "";
		}
		
		//唯一性：
		switch (idata['maxCount']){
			case "1":
				item_arr['Unique'] = "<p>唯一</p>";
			default:
				item_arr['Unique'] = "";
		}
		
		
		//部位:
		switch (idata['equipData']['inventoryType']){
			case "1":
				item_arr['inventory'] = "<p style='float:left;margin-top:0;'>头部</p>";
				break;
			case "2":
				item_arr['inventory'] = "<p style='float:left;margin-top:0;'>颈部</p>";
				break;			
			case "3":
				item_arr['inventory'] = "<p style='float:left;margin-top:0;'>肩部</p>";
				break;			
			case "4":
				item_arr['inventory'] = "<p style='float:left;margin-top:0;'>衬衣</p>";
				break;			
			case "5": case "20":
				item_arr['inventory'] = "<p style='float:left;margin-top:0;'>胸部</p>";
				break;			
			case "6":
				item_arr['inventory'] = "<p style='float:left;margin-top:0;'>腰部</p>";
				break;			
			case "7":
				item_arr['inventory'] = "<p style='float:left;margin-top:0;'>腿部</p>";
				break;
			case "8":
				item_arr['inventory'] = "<p style='float:left;margin-top:0;'>脚</p>";
				break;				
			case "9":
				item_arr['inventory'] = "<p style='float:left;margin-top:0;'>手腕</p>";
				break;				
			case "10":
				item_arr['inventory'] = "<p style='float:left;margin-top:0;'>手</p>";
				break;
			case "11":
				item_arr['inventory'] = "<p style='float:left;margin-top:0;'>手指</p>";
				break;
			case "12":
				item_arr['inventory'] = "<p style='float:left;margin-top:0;'>饰品</p>";
				break;
			case "14":
				item_arr['inventory'] = "<p style='float:left;margin-top:0;'>盾牌</p>";
				break;
			case "17":
				item_arr['inventory'] = "<p style='float:left;margin-top:0;'>双手</p>";
				break;						
			case "21":
				item_arr['inventory'] = "<p style='float:left;margin-top:0;'>主手</p>";
				break;					
			case "16": 
				item_arr['inventory'] = "<p style='float:left;margin-top:0;'>背部</p>";
				break;	
			case "22": case "23": 
				item_arr['inventory'] = "<p style='float:left;margin-top:0;'>副手</p>";
				break;
			case "24":
				item_arr['inventory'] = "<p style='float:left;margin-top:0;'>弹药</p>";
				break;
			case "26":
				item_arr['inventory'] = "<p style='float:left;margin-top:0;'>远程</p>";
				break;
			case "28":
				item_arr['inventory'] = "<p style='float:left;margin-top:0;'>圣物</p>";
				break;
			default:
				item_arr['inventory'] = "";		
		}
		
		//子类型:
		item_arr['subclassName'] = (idata['equipData']['subclassName']) ? "<p style='float:right;margin-top:0;'>"+idata['equipData']['subclassName']+"</p>" : "";
		//alert (idata['equipData']['inventoryType']);
		//alert (item_arr['inventory']);
		
		//护甲值:
		item_arr['armor'] = (idata['armor']) ? "<p>"+idata['armor']+"点护甲</p>" : "";
		//
		//属性值:
		item_arr['bonusStrength'] = (idata['bonusStrength']) ? "<p>"+idata['bonusStrength']+"力量</p>" : "";
		item_arr['bonusAgility'] = (idata['bonusAgility']) ? "<p>"+idata['bonusAgility']+"敏捷</p>" : "";
		item_arr['bonusStamina'] = (idata['bonusStamina']) ? "<p>"+idata['bonusStamina']+"耐力</p>" : "";
		item_arr['bonusIntellect'] = (idata['bonusIntellect']) ? "<p>"+idata['bonusIntellect']+"智力</p>" : "";
		item_arr['bonusSpirit'] = (idata['bonusSpirit']) ? "<p>"+idata['bonusSpirit']+"精神</p>" : "";
		/*bonustr = item_arr['bonusStrength']+item_arr['bonusAgility']+item_arr['bonusStamina']+item_arr['bonusIntellect']+item_arr['bonusSpirit'];
		alert (bonustr);*/
		//alert(idata['socketData']['socket']['0']['@attributes']['color']);
		
		//插槽:
		item_arr['socket'] = "";
		if(idata['socketData']){
			
			if(idata['socketData']['socket'].length){
				sL = idata['socketData']['socket'].length;
				socket = "";
				for(i=0;i<sL;i++){
					color = idata['socketData']['socket'][i]['@attributes']['color'];
					color_text = socketColor(color);
					socket = socket + "<p class='q0'><img src='"+root_url+"Public/js/wowAjax/style/images/armory/socket/socket_"+color+".gif'>"+color_text+"</p>";
				}
				item_arr['socket'] = socket;
			}
			else{
				color = idata['socketData']['socket']['@attributes']['color'];
				color_text = socketColor(color);
				item_arr['socket'] = "<p class='socket-"+color+"'><img src='"+root_url+"Public/images/wow/armory/socket/socket_"+color+".gif'>"+color_text+"</p>";
			}
			//alert (item_arr['socket']);
		}
		
		//耐久度:
		item_arr['durability'] = (idata['durability']) ? "<p>耐久度 "+idata['durability']['@attributes']['current']+"/"+idata['durability']['@attributes']['max']+"</p>" : "";
		//alert (item_arr['durability']);
		
		//职业:
		item_arr['class'] = (idata['allowableClasses']) ? "<p>职业: "+idata['allowableClasses']['class']+"</p>" : "";
		
		//需要等级:
		if(item_arr['level'] && item_arr['level']>0){
			item_arr['level'] = "<p>需要等级"+idata['requiredLevel']+"级</p>";
		}
		else{
			item_arr['level'] = "";
		}
		
		//攻击技能等级；
		item_arr['bonusHitRating'] =   (idata['bonusHitRating']) ? "<p class='q2'>装备: 命中等级提高"+idata['bonusHitRating']+"</p>" : ""; 
		item_arr['bonusHasteRating'] =   (idata['bonusHasteRating']) ? "<p class='q2'>装备: 急速等级提高"+idata['bonusHasteRating']+"</p>" : "";
		item_arr['bonusExpertiseRating'] =   (idata['bonusExpertiseRating']) ? "<p class='q2'>装备: 精准等级提高"+idata['bonusExpertiseRating']+"</p>" : "";
		item_arr['bonusResilienceRating'] =   (idata['bonusResilienceRating']) ? "<p class='q2'>装备: 韧性等级提高"+idata['bonusResilienceRating']+"</p>" : "";
        item_arr['bonusCritRating'] =   (idata['bonusCritRating']) ? "<p class='q2'>装备: 暴击等级提高"+idata['bonusCritRating']+"</p> \n" : "";
		item_arr['bonusDefenseSkillRating'] =   (idata['bonusDefenseSkillRating']) ? "<p class='q2'>装备: 防御等级提高"+idata['bonusDefenseSkillRating']+"</p>" : "";
		item_arr['bonusDodgeRating'] =   (idata['bonusDodgeRating']) ? "<p class='q2'>装备: 闪避等级提高"+idata['bonusDodgeRating']+"</p>" : "";
		item_arr['bonusParryRating'] =   (idata['bonusParryRating']) ? "<p class='q2'>装备: 招架等级提高"+idata['bonusParryRating']+"</p>" : "";
		item_arr['bonusBlockRating'] =   (idata['bonusBlockRating']) ? "<p class='q2'>装备: 盾牌格挡等级提高"+idata['bonusBlockRating']+"</p>" : "";
		
		//装备效果;
		item_arr['spellData'] = "";
		
		if(idata['spellData']){
			
			if(idata['spellData']['spell'].length){
				var spellData ="";	
				slen = idata['spellData']['spell'].length;
				for (i=0; i<slen; i++){
					spellData = spellData + "<p class='q2'>装备: "+idata['spellData']['spell'][i]['desc']+"</p>";
					
				}
				item_arr['spellData'] = spellData;
			}
			else{
				item_arr['spellData'] = "<p class='q2'>装备: "+idata['spellData']['spell']['desc']+"</p>";
			}
		}
		//alert (item_arr['spellData']);
		
		
		item_arr['bonusrating'] = item_arr['bonusHitRating']+item_arr['bonusHasteRating']+item_arr['bonusExpertiseRating']+item_arr['bonusResilienceRating']+item_arr['bonusCritRating']+item_arr['bonusDefenseSkillRating']+item_arr['bonusDodgeRating']+item_arr['bonusParryRating']+item_arr['bonusBlockRating']+item_arr['spellData'];
		//alert (item_arr['bonusrating']);
		item_arr['itemLevel'] = (idata['itemLevel']) ? "<p>物品等级:"+idata['itemLevel']+"级</p>" : "";
		
		item_str = "<div class='tips-in'>"+item_arr['name']+item_arr['bonding']+item_arr['Unique']+item_arr['inventory']+item_arr['subclassName']+"<div style='clear:both'>"+item_arr['armor']+item_arr['bonusStrength']+item_arr['bonusAgility']+item_arr['bonusStamina']+item_arr['bonusIntellect']+item_arr['bonusSpirit']+item_arr['socket']+item_arr['durability']+item_arr['class']+item_arr['level']+item_arr['bonusrating']+item_arr['itemLevel']+"</div></div>";
		 
		item_high = item_arr.length;
		
		item_return = new Array
		item_return['str'] = item_str;
		item_return['high'] = item_high;
		
		return item_return;
		
		
	}
	
function socketColor(scolor){
		switch (scolor){
					case "Red":
						scolor_text = " 红色插槽";
						break;
					case "Yellow":
						scolor_text = " 黄色插槽";
						break;
					case "Blue":
						scolor_text = " 蓝色插槽";
						break;
					case "Meta":
						scolor_text = " 多彩插槽";
						break;
					default:
						scolor_text = "";						
		}
		return scolor_text
	}
	
function tipsposition(tobj,tipsW,tipsH){
		var imgX = $(tobj).offset().left;
		var imgY = $(tobj).offset().top;
		var imgW = tobj.width;
		var imgH = tobj.height;
		var maxH = window.innerHeight;
		var maxW = window.innerWidth;
		
		mX = imgX + imgW;
		mY = imgY + imgH;
		//alert (imgY);
		//alert ("tips 的高度: "+tipsH+"\n mY的值: "+mY+"\n 屏幕的高度最大: "+maxH);
		
		if(tipsH + mY > maxH){
			
			mY = maxH - tipsH;
		}

		if(tipsW + mX > maxW){
			mX = imgX - tipsW;
		}
		var posi = new Array;
		posi['mX'] = mX;
		posi['mY'] = mY;
		mX = "";
		mY = "";
		return posi;
	}